package com.health;

import com.health.constant.RedisConstant;
import com.health.utils.QiniuUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Set;

public class ClearImgJob extends QuartzJobBean {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        Set<String> set=redisTemplate.opsForSet().difference(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(set!=null){
            for(String picName:set){
                QiniuUtils.deleteFileFromQiniu(picName);
                redisTemplate.boundSetOps(RedisConstant.SETMEAL_PIC_RESOURCES).remove(picName);
                System.out.println("自定义任务执行，清理垃圾图片："+picName);
            }
        }
    }
}

